package com.ruoyi.system.service.impl;

import com.ruoyi.system.domain.Message;
import com.ruoyi.system.domain.vo.Focus;
import com.ruoyi.system.domain.vo.MessageVo;
import com.ruoyi.system.mapper.MessageMapper;
import com.ruoyi.system.service.MessageService;
import com.ruoyi.system.service.RedisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class MessageServiceImpl implements MessageService {
    @Autowired
    private RedisService redisService;

    @Autowired
    private MessageMapper messageMapper;

    @Override
    public List<Message> selectUserSendOther(Long user, Long other) {
        return messageMapper.selectUserSendOther(user,other);
    }
    @Override
    public int insertMessage(Message message){
        return messageMapper.insertMessage(message);
    }

    @Override
    public List<MessageVo> selectNoReadMessage(Long user) {
        return messageMapper.selectNoReadMessage(user);
    }


    @Override
    public int updateMessageStatus(Long user, Long other) {
        return messageMapper.updateMessageStatus(user,other);
    }

    @Override
    public int deleteForListId(Long user, Long other) {
        List<Integer> integers = messageMapper.selectIdByUserAndReadStatus(user, other);
        return messageMapper.deleteForListId(integers);
    }

    @Override
    public int createInformationBox(Focus focus,Long user) {
        Boolean aBoolean = redisService.hHasKey("InformationBox: "+user.toString(),focus.getUserid().toString());
        if(aBoolean){
            return  1;
        }
        else{
            redisService.hSet("InformationBox: "+user.toString(),focus.getUserid().toString(),focus);
            return 0;
        }
    }

    @Override
    public Map<String, Object> getInformationBox(Long user) {
        Map<String, Object> stringObjectMap = redisService.hGetAll("InformationBox: "+user.toString());
        return stringObjectMap;
    }
}
